/**
 * Created by Roy on 16-4-14.
 */
import qiniu from "qiniu";

//需要填写你的 Access Key 和 Secret Key
qiniu.conf.ACCESS_KEY = 'Hjsoy5wnuUl-F1pffjejgrsf0oCcF6v3FZVnb9Om';
qiniu.conf.SECRET_KEY = 'FXtF54ZvWXxGo9HPabWm70BAg1b_UvnmL8YSZjhz';

//要上传的空间
var bucket = 'jianrmod';

//构建上传策略函数
function uptoken(bucket, key) {
    var putPolicy = new qiniu.rs.PutPolicy(bucket+":"+key);
    return putPolicy.token();
}

export function uploadFile(localFile, remoteFile) {
    return new Promise((resolve,reject)=> {
        var extra = new qiniu.io.PutExtra();
        qiniu.io.putFile(uptoken(bucket, remoteFile), remoteFile, localFile, extra, (err,data)=>{
            if (err) return reject(err);
            return resolve(data);
        });
    });
}


